<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="关键词" prop="jobName">
        <el-input
          v-model.trim="queryParams.jobName"
          placeholder="请输入要爬取的岗位名称"
          clearable
          style="width: 240px"
        />
      </el-form-item>

      <el-form-item label="省" prop="provinceId">
        <el-select @change="changeProvince"
          v-model="queryParams.provinceId"
          placeholder="省"
          clearable
          style="width: 120px"
        >
          <el-option
            v-for="dict in this.provinces"
            :key="dict.areaName"
            :label="dict.areaName"
            :value="dict.areaCode+','+dict.areaId+','+dict.areaName"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="城市" prop="city">
        <el-select
          v-model="queryParams.city"
          placeholder="城市"
          clearable
          style="width: 100px"
        >
          <el-option
            v-for="dict in this.cities"
            :key="dict.areaName"
            :label="dict.areaName"
            :value="dict.areaName"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="经验要求" prop="experience">
        <el-select
          v-model="queryParams.experience"
          placeholder="请选择经验要求"
          clearable
          style="width: 180px"
        >
          <el-option
            v-for="dict in dict.type.experience_time"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="学历要求" prop="degree">
        <el-select
          v-model="queryParams.degree"
          placeholder="学历要求"
          clearable
          style="width: 180px"
        >
          <el-option
            v-for="dict in dict.type.degree_level"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="行业" prop="industryType1">
        <el-select
          v-model="queryParams.industryType1"
          placeholder="行业"
          clearable
          style="width: 200px"
        >
          <el-option
            v-for="dict in this.industrys"
            :key="dict.industryType1"
            :label="dict.industryType1"
            :value="dict.industryType1"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >

      </el-form-item>
      <el-form-item>
        <download-excel
          class = "export-excel-wrapper"
          :data = "jobList"
          :fields = "tableHeader"
          :name =exportName>
          <el-button
            type="warning"
            icon="el-icon-download"
            size="mini"
          >本页导出</el-button>
        </download-excel>

      </el-form-item>

      <el-form-item>
        <download-excel
          class = "export-excel-wrapper"
          :fields = "tableHeader"
          :name =exportAsnName
          :data="jobExportList"
          id="aynExportId"
          :fetch="handleExport"
        >
          <el-button
            type="success"
            icon="el-icon-download"
            size="mini"
          >全部导出</el-button>
        </download-excel>

      </el-form-item>

    </el-form>


    <el-table border
      v-loading="loading"
      :data="jobList"
    >
      <el-table-column label="序号" type="index"  width="60" align="center">
        <template scope="scope">
          <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="职业名称"
        prop="jobName"
        :show-overflow-tooltip="true"
        width="155" align="center"
      />
      <el-table-column
        label="地区"
        prop="jobArea"
        :show-overflow-tooltip="true"
        width="100" align="center"
      />
      <el-table-column
        label="省份"
        prop="province"
        :show-overflow-tooltip="true"
        width="70" align="center"
      />
      <el-table-column
        label="城市"
        prop="city"
        :show-overflow-tooltip="true"
        width="70" align="center"
      />
      <el-table-column
        label="经验要求"
        prop="experience"
        :show-overflow-tooltip="true"
        align="center"
        width="105"
      />
      <el-table-column label="学历要求" prop="degree" align="center" width="80" />
      <el-table-column label="最低工资"  prop="jobSalaryMin"  align="center" width="80"></el-table-column>
      <el-table-column label="最高工资"  prop="jobSalaryMax"  align="center" width="80"></el-table-column>
      <el-table-column label="行业"  prop="industryType1"  align="center" width="150"></el-table-column>
      <el-table-column label="公司名称"  prop="companyName"  align="center" width="200" ></el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {
  listJob,exportList,
} from "@/api/sysFunction/functions";
import {
  listProvince,listCity,listIndustry
} from "@/api/common/common";



export default {
  name: "Role",
    dicts: ['experience_time', 'degree_level'],
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      provinces: [],
      cities: [],
      industrys: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      jobList: [],
      jobExportList: [],
      //下载有bug，第一次点击不下载
      exportCount: 0,
      exportName:"实时导出岗位信息"+new Date().getTime() +".xlsx",
      exportAsnName:"异步导出岗位信息"+new Date().getTime() +".xlsx",
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否显示弹出层(分配接口)
      openAuthApi: false,
      menuExpand: false,
      menuNodeAll: false,
      resourceExpand: true,
      resourceNodeAll: false,
      // 菜单列表
      menuOptions: [],
      // 资源列表
      resourceOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        jobName:'',
        provinceId: '',
        province: '',
        city: '',
        experience:'',
        degree:'',
        industryType1:''
      },
//导出表头
      tableHeader:
        {
          "职业名称":'jobName',
          "地区":'jobArea' ,
          "省份":'province',
          "城市" : 'city',
          "经验要求" :'experience',
          "学历要求": 'degree',
          "工资": 'provideSalary',
          "行业": 'industryType1',
          "公司名称": 'companyName',
        },
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 表单校验
      rules: {
        roleName: [
          { required: true, message: "角色名称不能为空", trigger: "blur" },
        ],
        roleKey: [
          { required: true, message: "权限字符不能为空", trigger: "blur" },
        ],
        roleSort: [
          { required: true, message: "角色顺序不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.getProvince();
    this.getIndustry();
  },
  methods: {

    /** 默认列表 */
    getList() {
      this.loading = true;
      listJob(this.queryParams).then(
        (response) => {
          this.jobList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },

    //获取省份
    getProvince(){
      listProvince().then(response => {
        this.provinces=response.data;
      });
    },

    //级联城市
    changeProvince(val){
      //点击省份的时候清空城市选项
      this.queryParams.city='';
      var split = val.split(",");
      var provinceId = split[1];
      this.queryParams.province=split[2];

      listCity(provinceId).then(response => {
        this.cities=response.data;
      });
    },

    //获取行业
    getIndustry(){
      listIndustry().then(response => {
        this.industrys=response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮（分配接口）
    cancelApiResource() {
      this.openAuthApi = false;
      this.reset();
    },
    // 表单重置
    reset() {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([]);
      }
      (this.menuExpand = false),
        (this.menuNodeAll = false),
        (this.resourceExpand = true),
        (this.resourceNodeAll = false),
        (this.queryParams={});
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      // this.getListByCondition();
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      // this.handleQuery();
    },

    /** 导出按钮操作 */
    async handleExport() {
      const res = await exportList(this.queryParams);
      this.jobExportList = res.data;
      return this.jobExportList;
    },

  }};
</script>
